#include "StdAfx.h"
#include "GameMap.h"
#include "XTPPropertyGridItemGridPos.h"

CGameMap::CGameMap()
: m_csMapSize(DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT), m_nGridSize(CMapGrid::DEFAULT_GRID_SIZE)
{
	m_DataGridInfo.Init();
}

CGameMap::~CGameMap()
{}
void CGameMap::SaveMap(CArchive& ar)
{
	ar << m_csMapSize << m_nGridSize;
	ar << m_GridStore.size();
	for (GridStore::iterator it = m_GridStore.begin(); it != m_GridStore.end(); ++it)
	{
		it->second.SaveData(ar);
		m_DataGridInfo.Add(it->second.m_GridData);
	}
	CString FilePath = ar.GetFile()->GetFilePath();
	FilePath += _T(".smap");
	
	m_DataGridInfo.Save(FilePath.GetString());
}
void CGameMap::LoadMap(CArchive& ar)
{
	ar >> m_csMapSize >> m_nGridSize;
	int nGrid;
	ar >> nGrid;
	for (int i = 0; i < nGrid; ++i)
	{
		CMapGrid stGrid;
		stGrid.LoadData(ar);
		m_GridStore.insert(std::make_pair(stGrid.m_GridData.nId.nId, stGrid));
	}
}